package com.emergency.evaluate.dao;

import com.emergency.evaluate.domain.Score;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by Administrator on 2020/3/16.
 */
public interface ScoreDao extends JpaRepository<Score,String>, JpaSpecificationExecutor<Score> {

    //根据评分表id删除对应的分数表
    @Modifying
    @Query(value = "delete FROM Score WHERE manual.id =:manualId ")
    void deleteAllByManualId(@Param ( "manualId" ) Long manualId);
    //根据想定ID对应的评分表删除对应的分数表
    @Modifying
    @Query(value = "delete FROM eva_manual WHERE scenar_id = ? ", nativeQuery = true)
    void deleteByManual(Long scenarId);

    //根据评分表编号ID 获取对应的分数表
    @Query(value = "SELECT s FROM Score s WHERE manual.id =:manualId")
    List<Score> findAllByManual(@Param ( "manualId" ) Long manualId);
    //根据提取指标ID删除相关分数
    @Modifying
    @Query(value = "delete FROM Score WHERE extract.id =:extractId ")
    void deleteByExtract(@Param ( "extractId" ) Long extractId);

    @Query(value = "select i from Score i where i.id=:id")
    Score findAllById(@Param ( "id" ) Long id);
}
